package com.cn.admin.controller;

import com.cn.admin.method.LabelMethod;
import com.cn.admin.unit.Tool;
import com.cn.admin.vo.label.LabelVo;
import com.cn.api.LabelService;
import com.cn.common.result.Result;
import com.cn.dto.LabelDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//import com.wanxi.unit.Tool;

@Api(tags = "标签信息")
@RestController
@RequestMapping("labela")
public class LabelController implements LabelMethod {
    @Autowired
    LabelService labelService;
    @ApiOperation("全部标签信息")
    @GetMapping("findAll")
    public Result findAll(int limit, int page){
        List<LabelDto> all = labelService.findAll(limit, page);
        return  Result.success(all);
    }
    @ApiOperation("删除标签")
    @PostMapping("delete")
    public Result delete(int id){
        int delete = labelService.delete(id);
        return Result.success(delete
        );
    }
    @ApiOperation("标签信息更改")
    @PostMapping("update")
    public Result update(LabelVo labelVo){
        LabelDto labelDto = Tool.VoToDto(labelVo);
        int update = labelService.update(labelDto);
        return  Result.success(update);
    }
    @ApiOperation("增加标签")
    @PostMapping("insert")
    public Result insert(LabelVo labelVo){
        LabelDto labelDto = Tool.VoToDto(labelVo);
        int insert = labelService.insert(labelDto);
        return Result.success(insert);
    }
    @ApiOperation("根据id查找")
    @GetMapping("findById")
    public Result findById(int id){
        LabelDto byId = labelService.findById(id);
        return Result.success(byId);
    }
}
